package com.klhappy.houyuan.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;

import com.klhappy.houyuan.R;
import com.klhappy.houyuan.adapter.ItemAdapter;
import com.klhappy.houyuan.bean.EvaluateBean;
import com.klhappy.houyuan.bean.GoodsAllBean;
import com.klhappy.houyuan.view.AbsActivity;
import com.klhappy.houyuan.view.UnfoldedListView;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by MrPu on 15/12/27.
 */
public class EvaluateDetailActivity extends AbsActivity {
    @InjectView(R.id.title)
    TextView title;
    @InjectView(R.id.tv_time)
    TextView tv_time;
    @InjectView(R.id.tv_sum)
    TextView tv_sum;
    @InjectView(R.id.tv_amount)
    TextView tv_amount;
    @InjectView(R.id.lv_content)
    UnfoldedListView lv_content;

    @OnClick(R.id.click_ra)
    public void click_ra() {
        finish();
    }

    @OnClick(R.id.btn_pay)
    public void btn_pay() {
        Intent intent = new Intent(this, RatingActivity.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable("goods", orderDetail);
        bundle.putSerializable("or_id", or_id);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    private ArrayList<EvaluateBean.OrderDetail> orderDetail;
    private ItemAdapter adapter;
    private String or_id;
    private String time;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_evaluatex);
        ButterKnife.inject(this);
        title.setText("订单详情");

        orderDetail = (ArrayList<EvaluateBean.OrderDetail>) getIntent().getSerializableExtra("goods");
        time = (String) getIntent().getSerializableExtra("time");
        or_id = (String) getIntent().getSerializableExtra("or_id");

        tv_time.setText(time);
        tv_sum.setText("共" + orderDetail.size() + "样商品");
        float acount = 0;
        for (int i = 0; i < orderDetail.size(); i ++){
            acount = acount + Float.parseFloat(orderDetail.get(i).getG_price())*Integer.parseInt(orderDetail.get(i).getNo());
        }
        tv_amount.setText("合计:  ￥" + acount);
        adapter = new ItemAdapter(this, orderDetail);
        lv_content.setAdapter(adapter);
        lv_content.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(EvaluateDetailActivity.this, XiangqingActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("goodId", orderDetail.get(position).getGoods_id() + "");
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
    }
}
